package org.example.news_check.ServiceImpl;

import org.example.news_check.Mapper.newsHistoryMapper;
import org.example.news_check.Pojo.newsHistory;
import org.example.news_check.Service.newsHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class newsHistoryServiceImpl implements newsHistoryService {

    @Autowired
    private newsHistoryMapper newsHistoryMapper;

    @Override
    public void save(Integer userId, String pageUrl) {
        newsHistory newsHistory = new newsHistory();
        newsHistory.setUserId(userId);
        newsHistory.setPageUrl(pageUrl);
        newsHistory.setVisitTime(LocalDateTime.now());

        // 确保通过实例调用非静态方法
        newsHistoryMapper.save(newsHistory);
    }

    @Override
    public List<newsHistory> findByUserId(Integer userId) {
        return newsHistoryMapper.findByUserId(userId);
    }
}
